<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="stylesheet" type="text/css" href="css/index.css"> -->
    <script type="text/javascript" src="js/tools.js"></script>
    <title>Document</title>
    <style type="text/css">
        .box {
            width: 400px;
            height: 400px;
            border: 1px solid #000;
            position: relative;
        }

        .box img {
            width: 400px;
            height: 400px;
        }

        .box .cover {
            width: 200px;
            height: 200px;
            background-color: rgba(0, 0, 0, 0.3);
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        .bigBox {
            width: 400px;
            height: 400px;
            border: 1px solid #000;
            position: absolute;
            left: 420px;
            top: 8px;
            overflow: hidden;
            display: none;
        }

        .bigBox img {
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="img/samll.jpg" alt="">
        <div class="cover"></div>
    </div>
    <div class="bigBox"><img src="img/big.jpg" alt=""></div>

    <script>
        document.querySelector('.box').addEventListener('mouseenter', function (e) {
            document.querySelector('.box .cover').style.display = 'block'
            $('.bigBox').style.display='block'
        }, false)
        document.querySelector('.box').addEventListener('mouseleave', function (e) {
            document.querySelector('.box .cover').style.display = 'none'
            $('.bigBox').style.display='none'
        }, false)
        document.querySelector('.box').addEventListener('mousemove', function (e) {
            let x=e.pageX - document.querySelector('.box').offsetLeft - document.querySelector('.cover').offsetWidth / 2
            let y=e.pageY - document.querySelector('.box').offsetTop - document.querySelector('.cover').offsetHeight / 2
            x=Math.min(Math.max(0,x),document.querySelector('.box').offsetWidth - document.querySelector('.cover').offsetWidth)
            y=Math.min(Math.max(0,y),document.querySelector('.box').offsetHeight - document.querySelector('.cover').offsetHeight)
            document.querySelector('.cover').style.left = x + 'px'
            document.querySelector('.cover').style.top = y + 'px'
            $('.bigBox img').style.left=-2*x+'px'
            $('.bigBox img').style.top=-2*y+'px'
        }, false)
    </script>
</body>

</html>